package com.lei.linearsearch;

import java.util.Random;

/**
 * @Author LeiXiaoLei
 * @Date 2022/7/14 18:33
 * @Version 1.0
 */
public class ArrayGenerator {

    private ArrayGenerator() {
    }

    public static Integer[] generatorOrderedArray(int n) {
        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; i++) {
            arr[i] = i;
        }
        return arr;
    }


    /**
     * 生成一个长度为n的随机数组，每个数字范围为[0,bound)
     *
     * @param n     数组长度
     * @param bound 随机数边界
     * @return 随机数组
     */
    public static Integer[] generatorRandomArray(int n, int bound) {
        Integer[] arr = new Integer[n];
        Random random = new Random();
        for (int i = 0; i < n; i++) {
            arr[i] = random.nextInt(bound);
        }
        return arr;
    }

    public static String[] generateRandomStringArray(int n, int w){

        // https://www.ascii-code.com/
        // 33-126 可打印字符
        String[] arr = new String[n];
        Random rnd = new Random();
        for(int i = 0; i < n; i ++){
            StringBuilder sb = new StringBuilder();
            for(int j = 0; j < w; j ++)
                sb.append((char)(rnd.nextInt(94) + 33));
            arr[i] = sb.toString();
        }
        return arr;
    }
}
